import ajax from "./ajax";
import BAPI from "./api";
import security from "./security";
import application from "./application-context";

import {Setting as LayerSetting} from "../lang/layers";
import Layers from "../lang/layers";

import Bamboo from "@/lang/bamboo";
import Eventbus from "@/lang/eventbus";

import MenuManager from "./menu-manager";

import Dictionary   from "@/lang/dict/dictionary";

// ----------------------------------------------------
//
// 负责协调各个组件，完成系统的初始配置
// ----------------------------------------------------

/**
 * 数据请求通用配置
 *
 * @param setting
 * @return {Promise<any>}
 */
let executor = function (setting) {
    return new Promise((resolve, reject) => {
        ajax(setting).then(res => {
            resolve(res);
        }).catch((err) => {
            reject(err);
        });
    })
}

/**
 * 工具类配置
 * --------------------------------------------------------------------------------------------
 */
if (LayerSetting) {
    const setting  = new LayerSetting();
    /* Layers 初始化ajax请求配置 */
    setting.setExecutor(executor);
    /* Layers 设置上下文路径 */
    setting.setContextPath(application.contextPath());

    /* 初始化所有数据字典 */
    // Layers.initializeDictionary();
    /* 初始化数据字典的Url */
    // Layers.setting.initializeDictionaryUrl('sys/dic/config/info');
}


/**
 * 初始化菜单栏配置
 * --------------------------------------------------------------------------------------------
 */
if (MenuManager) {
    // 初始化动态路由
    MenuManager.addDynamicMenus();
}


/**
 * 是否使用测试数据
 * --------------------------------------------------------------------------------------------
 */
if (BAPI) {
    window.BAPI = BAPI;
    if(application.isDebug()){
        // 使用测试数据
        BAPI.setDebug(true);
        //
        application.login();
    }
}

/**
 * 数据总线初始化
 * --------------------------------------------------------------------------------------------
 */
if (Eventbus) {
    window.Eventbus = Eventbus;
}

Dictionary.register("common_true", [
    {"label": "是", "value": 1},
    {"label": "否", "value": 0}
]);

// private static final String[] score = new String[]{"@", "稳定", "基本稳定", "欠稳定"};
Dictionary.register("ny_weather", [
    {"label": "阴", "value": 1},
    {"label": "晴", "value": 2},
    {"label": "多云", "value": 3},
    {"label": "小雨", "value": 4},
    {"label": "中雨", "value": 5},
    {"label": "阵雨", "value": 6},
    {"label": "大雨", "value": 7}
]);

Dictionary.register("ny_event", [
    {"label": "桥涵隧结构物及附属设施", "value": 1},
    {"label": "路面障碍物（占路堆物、占路作业等）", "value": 2},
    {"label": "路面污染（撒、滴、漏）", "value": 3},
    {"label": "路树倾倒", "value": 4},
    {"label": "设施倾倒", "value": 5},
    {"label": "路产损坏", "value": 6},
    {"label": "路基和边坡溜、塌方", "value": 7},
    {"label": "水沟堵塞", "value": 7},
    {"label": "其他", "value": 7}
]);


export default {Layers, Bamboo, Eventbus, MenuManager, BAPI, security, application}
